var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var i in t) t.hasOwnProperty(i) && (e[i] = t[i]);
    })(e, t);
}, function(e, t) {
    function i() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (i.prototype = t.prototype, 
    new i());
}), a = this && this.__decorate || function(e, t, i, o) {
    var r, n = arguments.length, a = n < 3 ? t : null === o ? o = Object.getOwnPropertyDescriptor(t, i) : o;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, i, o); else for (var s = e.length - 1; 0 <= s; s--) (r = e[s]) && (a = (n < 3 ? r(a) : 3 < n ? r(t, i, a) : r(t, i)) || a);
    return 3 < n && a && Object.defineProperty(t, i, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameManager"), s = e("EditView"), c = e("GameBlockEggs"), l = e("AudioManager"), d = e("PlayerModel"), u = e("PlayerMain"), p = e("WebManager"), h = cc._decorator, f = h.ccclass, g = h.property, m = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.gird = cc.v2(14, 14), e.size = 3, e.total = 4, e.root = null, e.before = null, 
        e.after = null, e.fillSprite = null, e.machineSkeleton = null, e.gameView = null, 
        e.type = 1, e.blocks = [], e;
    }
    return i(e, t), e.prototype.start = function() {}, e.prototype.init = function(e) {
        this.gameView = e, this.root.setPosition(cc.v2(80 * (this.gird.x + (this.size - 1) / 2) + 40 - this.gameView.map.width / 2, 80 * (this.gird.y + (this.size - 1) / 2) + 40 - this.gameView.map.height / 2)), 
        this.node.zIndex = 2 * -(this.gird.y + (this.size - 1) / 2);
        for (var t = this.gird.x; t < this.gird.x + this.size; t++) for (var i = this.gird.y; i < this.gird.y + this.size; i++) this.addBox(cc.v2(t, i));
    }, e.prototype.addBox = function(e) {
        var t = new cc.Node(), i = t.addComponent(c.default);
        i && (t.parent = this.gameView.layout, i.gird = e, i.gameEggs = this, t.setContentSize(80, 80), 
        t.zIndex = 2 * -e.y, t.setPosition(cc.v2(80 * i.gird.x + 40 - this.gameView.map.width / 2, 80 * i.gird.y + 40 - this.gameView.map.height / 2)), 
        i.type = s.BlockType.BLOCK, this.gameView.blocks.push(i), this.blocks.push(i));
    }, e.prototype.hurt = function() {
        var o = this;
        this.fillSprite.fillRange < 1 && (this.fillSprite.fillRange += 1 / this.total, p.default.getInstance().sentLog("尝试触发彩蛋"), 
        1 <= this.fillSprite.fillRange && (p.default.getInstance().sentLog("成功触发彩蛋"), this.gameView.appendSkeleton({
            url: "skeleton/机甲召唤输出/skeleton",
            root: this.gameView.node.getChildByName("ctl"),
            pos: cc.Vec2.ZERO
        }).then(function(e) {
            for (var t = 0; t < o.blocks.length; ) {
                var i = o.blocks[t];
                i.gird.x != o.gird.x && i.gird.x != o.gird.x + o.size - 1 || i.gird.y != o.gird.y && i.gird.y != o.gird.y + o.size - 1 ? (o.blocks.splice(t, 1), 
                i.doDestroy()) : (t++, o.gameView.appendSprite({
                    url: "texture/map/block/block_1_1",
                    root: i.node,
                    pos: cc.v2(0, -40)
                }).then(function(e) {
                    e.node.anchorY = 0, e.node.angle = -0;
                }));
            }
            o.node.zIndex = -50, e instanceof sp.Skeleton ? (r.default.getInstance().pause(), 
            l.default.getInstance().pauseBg(), l.default.getInstance().playAudio("机甲音效"), o.gameView.players.forEach(function(e) {
                return e.model.addBuffer(d.BufferType.执行);
            }), e.node.scale = 1.5, e.node.active = !0, e.setAnimation(0, "animation", !1), 
            e.setCompleteListener(function() {
                e.setCompleteListener(null), r.default.getInstance().resume(), l.default.getInstance().resumeBg(), 
                o.gameView.players.forEach(function(e) {
                    return e.model.removeBuffer(d.BufferType.执行);
                }), o.gameView.removeSkeleton(e.node), o.type = 2, o.before.active = !1, o.after.active = !0;
            })) : (o.before.active = !1, o.after.active = !0);
        })));
    }, e.prototype.checkPlayerDistance = function(e, t) {
        return void 0 === t && (t = 40), !(!e && !e.checkTarget(e)) && e.node.position.sub(this.node.position).mag() < t;
    }, e.prototype.doEnd = function() {
        this.type = 4, this.machineSkeleton.node.parent.destroy(), this.gameView.curPlayer.modelType = u.ModelType.MACHINE, 
        this.gameView.curPlayer.machineModel.initModel(), this.gameView.curPlayer.loadSkin(this.gameView.curPlayer.model.personIdx), 
        this.gameView.curPlayer.hpView.init(this.gameView.curPlayer.machineModel.MAX_HP);
    }, e.prototype.update = function() {
        var e, t = this;
        2 == this.type ? this.checkPlayerDistance(this.gameView.curPlayer, 80) && (this.type = 3, 
        this.gameView.curPlayer.model.addBuffer(d.BufferType.变身), this.gameView.curPlayer.model.addBuffer(d.BufferType.无敌), 
        this.gameView.curPlayer.sprite.node.active = !1, this.machineSkeleton.setAnimation(0, "animation4", !1), 
        this.machineSkeleton.setCompleteListener(function() {
            t.machineSkeleton.setCompleteListener(null), t.gameView.curPlayer.model.removeBuffer(d.BufferType.变身), 
            t.gameView.curPlayer.model.removeBuffer(d.BufferType.无敌), t.doEnd();
        })) : 3 == this.type && ((e = this.machineSkeleton.findBone("juese_root")) ? (e = this.gameView.layout.convertToNodeSpaceAR(this.machineSkeleton.node.convertToWorldSpaceAR(cc.v2(.5 * e.worldX, .5 * e.worldY))), 
        this.gameView.curPlayer.node.setPosition(e)) : this.doEnd());
    }, a([ g ], e.prototype, "gird", void 0), a([ g ], e.prototype, "size", void 0), 
    a([ g(cc.Node) ], e.prototype, "root", void 0), a([ g(cc.Node) ], e.prototype, "before", void 0), 
    a([ g(cc.Node) ], e.prototype, "after", void 0), a([ g(cc.Sprite) ], e.prototype, "fillSprite", void 0), 
    a([ g(sp.Skeleton) ], e.prototype, "machineSkeleton", void 0), a([ f ], e);
}(cc.Component);

n.default = m;